from math import *

class Vector(object):
	'''
	classdocs
	'''

	def __init__(self, x=0.0, y=0.0, z=0.0):
		'''
		Constructor
		'''
		if isinstance(x, list):
			if (len(x)>2):
				self.x = x[0]
				self.y = x[1]
				self.z = x[2]
		else:
			self.x = x
			self.y = y
			self.z = z

	def __str__(self):
		return '[' + str(self.x) + ', ' + str(self.y) + ', ' + str(self.z) + ']'

	def __add__(self, vector1):
		x = self.x + vector1.x
		y = self.y + vector1.y
		z = self.z + vector1.z
		return Vector(x,y,z)
	
	def __radd__(self, vector1):
		return self.__add__(vector1)

	def __sub__(self, vector1):
		x = self.x - vector1.x
		y = self.y - vector1.y
		z = self.z - vector1.z
		return Vector(x,y,z)
		
	def __rsub__(self, vector1):
		return self.__sub__(vector1)

	def __mul__(self, value):
		x = self.x * value
		y = self.y * value
		z = self.z * value
		return Vector(x,y,z)
		
	def __rmul__(self, vector1):
		return self.__mul__(vector1)

	def __floordiv__(self, value):
		x = self.x / value
		y = self.y / value
		z = self.z / value
		return Vector(x,y,z)
		
	def __rfloordiv__(self, vector1):
		return self.__floordiv__(vector1)

	def __div__(self, value):
		x = self.x / value
		y = self.y / value
		z = self.z / value
		return Vector(x,y,z)
		
	def __rdiv__(self, vector1):
		return self.__div__(vector1)

	def list(self):
		return [self.x,self.y,self.z]

	def multMatrix(self, matrix):
		x = self.x*matrix[0][0] + self.y*matrix[1][0] + self.z*matrix[2][0] + matrix[3][0]
		y = self.x*matrix[0][1] + self.y*matrix[1][1] + self.z*matrix[2][1] + matrix[3][1]
		z = self.x*matrix[0][2] + self.y*matrix[1][2] + self.z*matrix[2][2] + matrix[3][2]
		w = self.x*matrix[0][3] + self.y*matrix[1][3] + self.z*matrix[2][3] + matrix[3][3]
		return Vector(x/w,y/w,z/w)

	def multMatrix3x3(self, matrix):
		x = self.x*matrix[0][0] + self.y*matrix[1][0] + self.z*matrix[2][0]
		y = self.x*matrix[0][1] + self.y*matrix[1][1] + self.z*matrix[2][1]
		z = self.x*matrix[0][2] + self.y*matrix[1][2] + self.z*matrix[2][2]
		return Vector(x,y,z)

	def crossProduct(self, vector1):
		x = self.y*vector1.z - self.z*vector1.y
		y = self.z*vector1.x - self.x*vector1.z
		z = self.x*vector1.y - self.y*vector1.x
		return Vector(x,y,z)

	def scalarProduct(self, vector1):
		return self.x*vector1.x + self.y*vector1.y + self.z*vector1.z

	def module(self):
		return sqrt(self.x*self.x + self.y*self.y + self.z*self.z)

	def normalize(self):
		modu = self.module()
		self.x /= modu
		self.y /= modu
		self.z /= modu
